﻿/*                              
   Copyright 2011 Nils Kopal, Christopher Krüger, Simone Sauer, Dennis Nolte, Uni Duisburg-Essen

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.IO;
using Sharebert.SearchLibrary.Interfaces;

namespace Sharebert.SearchLibrary
{

    public class Message : IMessage
    {
        public const string COMMAND_FILE_OFFER = "FILE-OFFER";

        public const string COMMAND_SEARCH_REQUEST = "SEARCH-REQUEST";

        public const string COMMAND_SEARCH_RESPONSE = "SEARCH-RESPONSE";
        

        #region Constructors

        /// <summary>
        /// Initialize a new instance of Message class. This object is used to send messages over the network.
        /// </summary>
        /// <param name="header">The header of the message</param>
        /// <param name="payload">The payload of the message</param>
        /// <exception cref="ArgumentNullException">header or payload is null</exception>
        public Message(Header header, byte[] payload)
        {
            if (header == null)
            {
                throw new ArgumentNullException("header");
            }
            if (payload == null)
            {
                throw new ArgumentNullException("payload");
            }

            this.Header = header;
            this.Payload = payload;
        }

        #endregion


        public override String ToString()
        {
            String s = this.Header.ToString() + Environment.NewLine + Environment.NewLine;
            s += "### Payload ###" + Environment.NewLine + "Bytes received: " + this.Payload.Length;
            return s;
        }


        #region Properties and private member

        /// <summary>
        /// The message header.
        /// </summary>
        public IHeader Header { get; private set; }

        /// <summary>
        /// The message payload.
        /// </summary>
        public byte[] Payload { get; private set; }

        #endregion

    }
}
